package com.ml.doctor.view;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;

import com.ml.doctor.R;
import com.ml.doctor.bean.ZhiChenBean;

import java.util.List;

import butterknife.OnClick;

/**
 * Created by kun on 17/12/5.
 */

public class PickSelectZCPop extends PopupWindow implements View.OnClickListener, PickerView.OnItemSelectedListener {
    PickerView pickview;
    ImageView cancelImage;
    ImageView confirmImage;
    private Activity activity = null;
    ConfirmListen confirmListen;
    List<ZhiChenBean> list;
    int p;

    public PickSelectZCPop(Activity activity) {
        this.activity = activity;
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(activity).inflate(R.layout.pop_select_one, null);
        setContentView(view);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setFocusable(true);
        setBackgroundDrawable(new ColorDrawable(0));
        setTouchable(true);

        pickview = (PickerView) view.findViewById(R.id.pickview);
        pickview.setOnSelectListener(this);


        confirmImage = (ImageView) view.findViewById(R.id.confirm_image);
        confirmImage.setOnClickListener(this);

        cancelImage = (ImageView) view.findViewById(R.id.cancel_image);
        cancelImage.setOnClickListener(this);
    }

    public void setData(List<ZhiChenBean> list) {
        this.list = list;
        pickview.setList(list, 0);
    }

    @Override
    public void onItemSelected(PickerView pickView, String text, int position) {
        p = position;
    }

    public void setConfirmListen(ConfirmListen confirmListen) {
        this.confirmListen = confirmListen;
    }

    @OnClick({R.id.cancel_image, R.id.confirm_image})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cancel_image:
                dismiss();
                break;
            case R.id.confirm_image:
                if (confirmListen != null)
                    confirmListen.onConfirmListen(p);
                dismiss();
                break;
        }
    }

    public interface ConfirmListen {
        void onConfirmListen(int p);
    }


}
